package main

import (
	"fmt"
	"log"
	"time"
)

func main() {
	timeout := make(chan bool, 1)

	ch := make(chan int)
	defer func() {
		fmt.Println("出错退出线程")
		if err := recover(); err != nil {
			fmt.Println(err)
		}
	}()

	go func() {
		for {
			time.Sleep(3e9) // sleep 3 seconds
			timeout <- true
			select {
			case <-ch:
			case <-timeout:
				fmt.Println("timeout!")
				log.Println("结束")
			}
		}
	}()
	select {}

}
